package com.jn.exam.oss.schedule;

import com.jn.exam.oss.utils.GetToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;

/**
 * @author 江南大学1033190417
 * @date 2022/1/29 23:51
 */
@Component
@Slf4j
public class ScheduledTask {

    @Value("${baiduyun.api.API_KEY}")
    private String api_key;

    @Value("${baiduyun.api.SECRET_KEY}")
    private String secret_key;

    private String assess_token;

    @Scheduled(cron = "0 0 0 1/28 * ? ")
    public void task1(){
        this.assess_token= GetToken.getAuth(api_key,secret_key);
        log.info("更新assess_token:{}",this.assess_token);
    }

    @PostConstruct //项目启动后执行的方法
    public void task(){
        this.assess_token= GetToken.getAuth(api_key,secret_key);
        log.info("项目启动获得初始assess_token:{}",this.assess_token);
    }

    public String getAssess_token(){
        return this.assess_token;
    }
}
